package com.example.demo_mysql_mybatisplus.configs.threadpool;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("threadpool")
public class ThreadpoolController {
    /** spring 提供的线程池 */
    @Autowired
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    // 调用线程池执行任务
    @GetMapping("/test")
    public void test(){
        threadPoolTaskExecutor.execute(() -> {
            try {
                // 业务逻辑
                log.info("spring线程池执行 1 " );
            } catch (Exception e) {
                log.error("spring线程池执行异常", e);
            }
        });
        threadPoolTaskExecutor.execute(() -> {
            try {
                // 业务逻辑
                log.info("spring线程池执行 2 " );
            } catch (Exception e) {
                log.error("spring线程池执行异常", e);
            }
        });
    }
}